import { Component, OnInit } from '@angular/core';
import { Record} from '../record';
import { RecordsService} from '../service/records.service';

@Component({
  selector: 'app-record-check',
  templateUrl: './record-check.component.html',
  styleUrls: ['./record-check.component.css']
})
export class RecordCheckComponent implements OnInit {
  bid: string;
  pid: number;
  bdate: string;
  rdate: string;
  realDate: string;
  record: Record;
  records: Record[];
  temp: Record[];
  constructor(private recordsService: RecordsService) { }

  onSubmit() {
    this.record = {
      id: 1,
      bid: '12',
      pid: 123,
      bdate: '1234',
      rdate: '12345',
      realDate: '123456'
    };
    this.record.bid = this.bid;
    this.record.pid = this.pid;
    this.record.bdate = this.bdate;
    this.record.rdate = this.rdate;
    this.record.realDate = this.realDate;
    this.recordsService.getRecordsByConstraint(this.record).then(res => {
      console.log(res);
      this.records = res;
    });
    this.record.bid = undefined;
    this.record.pid = undefined;
    this.record.bdate = undefined;
    this.record.rdate = undefined;
    this.record.realDate = undefined;
    this.bid = undefined;
    this.pid = undefined;
    this.bdate = undefined;
    this.rdate = undefined;
    this.realDate = undefined;
  }

  ngOnInit() {
    this.recordsService.getRecords().then(res => {
      this.records = res;
    });
  }

}
